﻿using System;
using System.Linq;
using System.Web.UI.WebControls;

namespace LMS.SMSH.WEB
{
    public partial class StuMessageList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // 绑定gvStuMessage数据
                binggvStuMessage();
            }
        }

        /// <summary>
        /// 绑定gvStuMessage数据
        /// </summary>
        private void binggvStuMessage()
        {
            var query = from msg in LMSDataContext.GetLMSDB.TB_Message
                        where msg.mesStuNo.Equals(Session["studentID"].ToString())
                        select new
                        {
                            msg.mesId,
                            msg.mesAdminId,
                            msg.mesDetail,
                            msg.mesReply,
                            msg.mesStatus,
                            msg.mesStuNo,
                            msg.mesTime,
                            msg.mesTitle
                        };
            gvStuMessage.DataSource = query;
            gvStuMessage.DataKeyNames = new string[] { "mesId" };
            gvStuMessage.DataBind();

        }

        /// <summary>
        /// 行数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvStuMessage_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //鼠标悬停变色
                e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor;this.style.backgroundColor='#FF1199';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG;");
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvStuMessage_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvStuMessage.PageIndex = e.NewPageIndex;
            binggvStuMessage();
        }


    }
}